package com.ucpaas.sms.action.auditorKeyWord;

import com.jsmsframework.audit.entity.JsmsAuditKeywordCategory;
import com.jsmsframework.audit.exception.JsmsAuditKeywordCategoryException;
import com.jsmsframework.common.dto.ResultVO;
import com.ucpaas.sms.action.BaseAction;
import com.ucpaas.sms.service.auditorKeyWord.AuditorKeyWordService;
import com.ucpaas.sms.util.web.StrutsUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

@Controller
@Scope("prototype")
@Results({
})
public class AuditKeyWordCategoryAction extends BaseAction {


    private static Logger logger = LoggerFactory.getLogger(AuditKeyWordCategoryAction.class);


    @Autowired
    private AuditorKeyWordService auditorKeyWordService;

    /**
     * 删除审核关键字分类
     */
    @Action("/auditKeyWordCategory/delete")
    public void deleteCategory() {
        String idStr = StrutsUtils.getParameter("categoryId");
        ResultVO resultVO = new ResultVO();
        if(StringUtils.isBlank(idStr)){
            resultVO.setMsg("删除关键字失败，id="+idStr);
            resultVO.setFail(true);
        }else {
            try{
                resultVO = auditorKeyWordService.deleteCategory(Integer.valueOf(idStr));
            }catch (Exception e){
                logger.error("删除类别失败",e);
                if(e instanceof JsmsAuditKeywordCategoryException)
                    resultVO = ResultVO.failure(e.getMessage());
                else
                    resultVO = ResultVO.failure("删除类别失败");
            }
        }
        StrutsUtils.renderJson(resultVO);
    }

}
